﻿using System;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Windows.Controls;
using System.Windows.Data;

namespace Chambills.Present.Validation
{
    /// <summary>
    /// Use to safely read errors in ErrorTemplates
    /// </summary>
    public class ErrorContentConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {

            var errors = value as ReadOnlyObservableCollection<ValidationError>;

            if (errors == null) return "";



            return errors.Count > 0 ? errors[0].ErrorContent : "";

        }



        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {

            throw new NotImplementedException();

        }

    }
}